import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.swing.JComponent;

import org.imgscalr.Scalr;
import org.imgscalr.Scalr.Method;


class MonsterImage extends JComponent {

    public MonsterImage() {
    	File[] imgs = monsterDir.listFiles();
		int n = new Random().nextInt(imgs.length);
		try {
			BufferedImage temp = ImageIO.read(imgs[n]);
			monster = Scalr.resize(temp, Method.QUALITY, 200);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
    
    public void changeMonster(){
    	File[] imgs = monsterDir.listFiles();
		int n = new Random().nextInt(imgs.length);
		try {
			BufferedImage temp = ImageIO.read(imgs[n]);
			monster = Scalr.resize(temp, Method.QUALITY, 200);
		} catch (IOException e) {
			e.printStackTrace();
		}
		repaint();
    }

    @Override
    public Dimension getMinimumSize() {
        return new Dimension(100, 100);
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(monster.getWidth(), monster.getHeight());
    }
    
    @Override
    public int getWidth() {
    	return monster.getWidth();
    }
    
    @Override
    public int getHeight() {
    	return monster.getHeight();
    }

    @Override
    public void paintComponent(Graphics g) {
    	super.paintComponents(g);
		g.drawImage(monster, 0, 0, null);
    }
    
    private BufferedImage monster;
    private static final File monsterDir = new File("Monster");
    private static final long serialVersionUID = 1L;
}
